<?php

/**
 * Abstract storage class
 *
 * @author nam.ngvan@hotmail.com
 */
class Logger
{

	const ERROR = 'ERROR';

	const NOTICE = 'NOTICE';

	const WARNING = 'WARNING';

	const INFO = 'INFO';

	const DEBUG = 'DEBUG';

	private static $_instances = array();

	/**
	 * @var $name or $config
	 */
	static public function instance($name = null, $config = null)
	{
		if (null == $name)
		{
			$name = LOG_ADAPTER;
		}
		if (isset(self::$_instances[$name]))
		{
			return self::$_instances[$name];
		}

		$engine = isset($config['engine']) ? $config['engine'] : $name;

		$class = 'Log_Adapter_' . ucfirst($engine);

		return self::$_instances[$name] = new $class($name, $config);
	}

	static public function write($level, $message)
	{
		self::instance() -> write($level, $message);
	}

}
